﻿namespace Hanoi
{
    internal class Program
    {
        /// <summary>
        /// 汉诺塔游戏解析
        /// </summary>
        //移动次数
        static int Count=0;
        //主函数控制输入输出
        static void Main(string[] args)
        {
            Console.WriteLine("请输入汉诺塔层数");
            int num = int.Parse(Console.ReadLine());
            Console.WriteLine("操作步骤是：");
            Hanoi(num,'A','B', 'C');
            Console.WriteLine($"操作次数为：{Count}");
        }
        //移动函数
        public static void Move(char A, char B)
        {
            Console.WriteLine($"{A}->{B}");
            //每移动一次，计次加一
            Count++;
        }

        public static void Hanoi(int num, char A, char B, char C)
        {
            //退出递归
            if (num == 1)
            {
                Move(A, C);               
            }
            //递归
            else
            {
                Hanoi(num - 1, A, C, B);
                Move(A, C);                
                Hanoi(num - 1, B, A, C);
                
            }
        }

    }
}